package uet.sort;

import uet.sort.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LogSortingActivity extends Activity implements OnClickListener {
	private static final int SELECTIONSORT = R.id.algorithm1;
	private static final int QUICKSORT = R.id.algorithm2;
	private static final int SHELLSORT = R.id.algorithm3;

	private TextView nameAlgoSort1, nameAlgoSort2, logSort;
	private Button reset;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_logsort);
		logSort = (TextView) findViewById(R.id.tVlogSort);
		nameAlgoSort1 = (TextView) findViewById(R.id.tVnameAlgoSort3);
		nameAlgoSort2 = (TextView) findViewById(R.id.tVresultAlgoName);
		reset = (Button) findViewById(R.id.reset);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// Get algorithm chosen
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		// Show mesg algorithm chosen to screen
		switch (bundle.getInt("ALGORITHM")) {
		case SELECTIONSORT:
			nameAlgoSort1.setText("The Selection Sort is chosen");
			nameAlgoSort2.setText("Selection Sort result");
			break;
		case QUICKSORT:
			nameAlgoSort1.setText("The Quick Sort is chosen");
			nameAlgoSort2.setText("Quick Sort result");
			break;
		case SHELLSORT:
			nameAlgoSort1.setText("The Shell Sort is chosen");
			nameAlgoSort2.setText("Shell Sort result");
			break;
		default:
			break;
		}
		logSort.setText(bundle.getString("LOGSORTING"));
		reset.setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.reset:
			Context context = arg0.getContext();
			Intent intent = new Intent(context,
					ChooseAlgorithmSortActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			context.startActivity(intent);
			break;
		default:
			break;
		}
	}

}
